home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Demos / OOFILE / Buildable, limited OOFILE / samples / ooftst02.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-27  |  1.7 KB  |  64 lines  |  [TEXT/CWIE]

  1. // Copyright 1994 A.D. Software. All Rights Reserved
  2.  
  3. // OOFTEST2
  4.  
  5. // This sample tests the database backend by creating a pair of tables
  6. // and storing and retrieving indexed data via traversal paths.
  7.  
  8. // Simple stream I/O is used to interact with the user.
  9. #include "oofile.hpp"
  10.  
  11. #include "ooftst02.inc"
  12.  
  13. int main()
  14. {
  15.     cout << "OOFILE Validation Suite - Test 2\n"
  16.          << "Simple test to store some data and retrieve it" << endl
  17.          << "using a relation joining over a field and showing" << endl
  18.          << "iterators on related tables and 1-many relations" << endl << endl;
  19.     
  20.     if (dbConnect::fileExists("ooftst02.db"))
  21.         theDB.openConnection("ooftst02.db");
  22.     else {
  23.         theDB.newConnection("ooftst02.db");
  24.         People.AddTest2Data();
  25.     }
  26.  
  27.     People.sortBy(People.LastName);
  28.     People.start(); 
  29.     while (People.more()) {
  30.         cout << People.PatientNo << '\t' 
  31.              << People.LastName << endl;
  32.         if (People.Visits.count()==0)
  33.             cout << "no visits" << endl;
  34.         else {
  35.             People.Visits.start(); 
  36.             while (People.Visits.more()) {
  37.                 cout << '\t' << People.Visits->VisitDate() << '\t'
  38.                       << People.Visits->Why() << endl;
  39.                 People.Visits.next();
  40.             }
  41.         }
  42.         cout << endl;
  43.         People.next();
  44.     }
  45.  
  46.     cout << endl << "Now repeating the process using a dbView instead of explicitly" 
  47.          << endl << "iterating over the related file." << endl;
  48.     dbView relatedVisits(People.Visits);
  49.     relatedVisits << People.Visits->VisitDate() << People.Visits->Why();
  50.     People.start(); 
  51.     while (People.more()) {
  52.         cout << People.PatientNo << '\t' 
  53.              << People.LastName << endl;
  54.         if (relatedVisits.source()->empty())
  55.             cout << "no visits" << endl;
  56.         else 
  57.             cout << relatedVisits << endl;
  58.         cout << endl;
  59.         People.next();
  60.     }
  61.     cout << "Test Completed" << endl;
  62.     
  63.     return EXIT_SUCCESS;
  64. }